package wator.model;

/**
 * This class encapsulates a agent configurations. This is extrinsic for all
 * agents of the same type. This data type is used as element in the set
 * of agent configurations in the singleton {@link AvailableAgents}.
 * 
 * @see AvailableAgents
 * @see Agent
 */
public class AgentConfiguration {

	private Agent template;
	private boolean enabled;
	private int initPopSize;
	
	/**
	 * Sole constructor. Uses the template agent and fetches the default
	 * values for the enabled status and the initial population probability.
	 * 
	 * @param template the template agent used for this configuration
	 * @throws NullPointerException if <code>template</code> is null
	 */
	public AgentConfiguration (Agent template) {
		enabled = template.isDefaultEnabled();
		initPopSize = Constants.DEFAULT_INITIAL_POPULATION_SIZE;
		this.template = template;
	}
	
	/**
	 * Get the template individual for this species. If a individual breads,
	 * this template is cloned, just the direction and position vector are
	 * adjusted.
	 * 
	 * @return the agent template
	 */
	public Agent getTemplate() {
		return template;
	}
	
	/**
	 * Return TRUE if the agent species is enabled, FALSE otherwise. If a
	 * species is not enabled, it means that it did, does and will not exist 
	 * in the ecosystem of wator until it is enabled in the user interface.
	 * 
	 * @return true if this species is enabled
	 */
	public boolean isEnabled() {
		return enabled;
	}
	
	/**
	 * Setter method for <code>enabled</code>. This only changes the status of
	 * this agent in the model, but does not affect side effects in the user
	 * interface or in the population. However, observers are notified when
	 * species are enabled or disabled.
	 * 
	 * @param enabled the new enabled value
	 */
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	/**
	 * Return the the initial distribution number. This is the number of 
	 * individuals of this species at the begin of the simulation.
	 * 
	 * @return the initial number of individuals of this species 
	 * @see Population#repopulate()
	 */
	public int getInitialPopulationSize() {
		return initPopSize;
	}
	
	/**
	 * Setter method for the initial size of the population. This is the number 
	 * of individuals of this species at the begin of the simulation. Note that
	 * changing this value affects the behavior of the program not until 
	 * {@link Population#repopulate()} is called. Further note that this method
	 * does not include any higher level sanity checks (such as that the sum of
	 * this value of all enabled agents is smaller than the number of cells). 
	 * 
	 * @param initPopProb the new initial distribution probability
	 * @see Population#repopulate()
	 */
	public void setInitialPopulationSize(int initPopSize) {
		if (initPopSize >= 0) {
			this.initPopSize = initPopSize;
		}
	}
}
